$(document).ready(function(){
  var menu_height=$(document).height();
  $("#left-menu").css("height",menu_height+"px");
  find_url_id();
  console.log($("#info_name").val());
});

//左侧菜单始终保持100%高度
$(document).scroll(function(){
  var menu_height=$(document).height();
  $("#left-menu").css("height",menu_height+"px");
});

function topbtn(){
  if($("#topbar-ul").css("display")=="none"){
    $("#topbar-ul").css("display","block");
  }else{
    $("#topbar-ul").css("display","none");
  }

}
function find_url_id(){
  var url_str=window.location.href;
  var url_all=url_str.split("?")[1];
  var url_id=url_all.split("=")[1];
  //console.log(url_id);
  $.ajax({
    url: '/company_list',
    type: 'get',
    success: function(data,status){
      if(status == 'success'){
        console.log(data);
        for(var i in data){
          if(data[i]._id==url_id){
            $("#cms-topname").html(data[i].name);
            $("#cms-topname").attr("href","/company_info?id="+data[i]._id);
            $("#info_name").val(data[i].name);
            $("#info_fullname").val(data[i].fullname);
            $("#info_address").val(data[i].address);
            $("#info_website").val(data[i].website);

            $("#info_corporate").val(data[i].corporate);
            $("#info_position").val(data[i].contact_position);
            $("#info_field").val(data[i].business_field);

            $("#contact_name").val(data[i].contact_name);
            $("#contact_job").val(data[i].contact_position);
            $("#contact_phone").val(data[i].contact_mobile);
            $("#contact_tax").val(data[i].contact_tax);
            $("#contact_email").val(data[i].contact_email);
          }
        }
      }
      get_company_picse($("#info_name").val());
    },
    error: function(data,err){
      console.log(data);
    }
  });
}

function get_company_picse(name){
  var company_info = {
    name: name
  }
  $.ajax({
    url: '/company_pics',
    type: 'get',
    data: company_info,
    success: function(data,status){
      // data.logo_str
      // data.license_str
      if(status == 'success'){
        console.log(data);
        $("#licence-image").attr("src",data.license_str);
        $("#logo-image").attr("src",data.logo_str);
        //document.getElementById("yzm-image").src = data.logo_str;
        /*document.getElementById("licence-image").src = data.license_str;*/
      }
    },
    error: function(data,err,text){
      console.log(data.responseText);
    }
  });
}
